from django.contrib import admin

from apps.rbac.models import Role, Menu, Operate, MenuOperate, SensitiveField, MenuSensitiveField, \
    UserMenuSensitiveField


@admin.register(Role)
class RoleAdmin(admin.ModelAdmin):
    list_display = ('code', 'name_zh', 'name_en')
    # fieldsets = (None, {'fields': ('code', 'name_zh', 'name_en', 'is_admin')}),
    # autocomplete_fields = ('menu_operate',)
    search_fields = ('code', 'name_zh', 'name_en')


@admin.register(Menu)
class MenuAdmin(admin.ModelAdmin):
    list_display = ('code', 'name', 'name_en', 'content', 'is_active', 'is_green_light')
    search_fields = ('code', 'name', 'is_active')


@admin.register(Operate)
class OperateAdmin(admin.ModelAdmin):
    list_display = ('code', 'name', 'name_en')


@admin.register(MenuOperate)
class MenuOperateAdmin(admin.ModelAdmin):
    list_display = ('menu', 'operate', 'url', 'method', 'is_node')
    list_filter = ('menu',)
    search_fields = ['menu']


@admin.register(SensitiveField)
class SensitiveFieldAdmin(admin.ModelAdmin):
    list_display = ('code', 'name', 'name_en', 'field_type')


@admin.register(MenuSensitiveField)
class MenuSensitiveFieldAdmin(admin.ModelAdmin):
    list_display = ('menu', 'sensitive_field')
    list_filter = ('menu',)
    search_fields = ['menu']


@admin.register(UserMenuSensitiveField)
class UserMenuSensitiveFieldAdmin(admin.ModelAdmin):
    list_display = ('user', 'menu_sensitive_field', 'permission_type')
    list_filter = ('user',)
    search_fields = ['user']
